home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir30 / eerems11.zip / EER_INTF.C < prev    next >
C/C++ Source or Header  |  1994-10-23  |  4KB  |  149 lines

  1. /* ***************************************************************
  2.  
  3. An AutoCAD ADS program to remove "extra entities"
  4.  
  5. This module contains the interface function EEREM that may be
  6. called from ADS or LISP
  7.  
  8. Jon Fleming    CIS 70334,2443    July 19, 1994
  9.  
  10. Public Domain; Please give me credit if you use this or any
  11. significant portion of it
  12.  
  13. Revision history:
  14.  
  15. July 19, 1994  Version 1.0: Initial release
  16.  
  17. October 23, 1994 Version 1.1: Modified EER_CORE.C to handle negative line
  18.     endpoints properly, and to avoid checking for entities to remove when
  19.     no entities were selected in the "candidates for removal" selection set.
  20.     Modified EER_CORE.C and EEREM.H to include version number report when
  21.     DoEntityRemoval starts.
  22.  
  23. *********************************************************** */
  24.  
  25. #include  "adslib.h"
  26. #include "eerem.h"
  27.  
  28. /* Indicators for whether to consider layer, linetype, and/or color */
  29.  
  30. extern int CheckLayer, CheckLType, CheckColor;
  31.  
  32. /* Tolerance within which numbers are considered equal (at least, that's
  33.    approximately what this is; see below for more detail)  */
  34.  
  35. extern ads_real Tolerance;
  36.  
  37. /* Function prototypes */
  38.  
  39. int eerem ();
  40.  
  41. /* Function to perform Extra Entity Removal on a supplied selection
  42.    set.  Callable from AutoLISP or another ADS app.
  43.  
  44.    AutoLISP usage:
  45.  
  46.    (eerem sel_set checklayer checkltype checkcolor tolerance)
  47.  
  48.    where:
  49.  
  50.    sel_set is a selection set, and is required.
  51.  
  52.    checklayer is NIL to count entities on different layers as the same,
  53.    non-NIL to count entities on different layers as different.  checklayer
  54.    is optional (default NIL) unless one or more of the following arguments
  55.    are supplied.
  56.  
  57.    checkltype is NIL to count entities with different linetypes as the same,
  58.    non-NIL to count entities with different linetypes as different.  checkltype
  59.    is optional (default NIL) unless one or more of the following arguments
  60.    are supplied.
  61.  
  62.    checkcolor is NIL to count entities with different colors as the same,
  63.    non-NIL to count entities with different colors as different.  checkcolor
  64.    is optional (default NIL) unless one or more of the following arguments
  65.    are supplied.
  66.  
  67.    tolerance is a real number that measures how close points must be to be
  68.    considered the same (well, approximately; see the DOC file for more
  69.    detail).  tolerance is optional.  The default is 0.00001.
  70.  
  71.    ADS usage:
  72.  
  73.    Call eerem through ads_invoke with a list corresponding to the AutoLISP
  74.    parameters.
  75.  
  76.    Return value:
  77.  
  78.    NIL / RSERR if an error was detected
  79.  
  80.    T / RSRSLT otherwise
  81. */
  82.  
  83. int eerem () {
  84.  
  85.    struct resbuf *Argument = NULL;
  86.  
  87.    int ArgNum = 1, stat = RSRSLT;
  88.  
  89.    ads_name SelSet;
  90.  
  91.    /* Assume the worst */
  92.  
  93.    ads_retnil();
  94.  
  95.    if ((Argument = ads_getargs()) == NULL) {
  96.       ads_printf("\nEEREM error:  no arguments\n");
  97.       return (RSERR);
  98.    }
  99.  
  100.    if (Argument->restype != RTPICKS) {
  101.       ads_printf("\nEEREM error:  first argument must be a selection set\n");
  102.       return (RSERR);
  103.    }
  104.  
  105.    ads_name_set(Argument->resval.rlname, SelSet);
  106.  
  107.    while ((Argument = Argument->rbnext) != NULL) {
  108.  
  109.       /* Arguments 2 through 4 we don't care about the type unless they're
  110.          NIL.  Argument 5 must be a real */
  111.  
  112.       switch (ArgNum = ++ArgNum) {
  113.          case 2: {
  114.             CheckLayer = (Argument->restype == RTNIL) ? FALSE : TRUE;
  115.             break;
  116.          }
  117.          case 3: {
  118.             CheckLType = (Argument->restype == RTNIL) ? FALSE : TRUE;
  119.             break;
  120.          }
  121.          case 4: {
  122.             CheckColor = (Argument->restype == RTNIL) ? FALSE : TRUE;
  123.             break;
  124.          }
  125.          case 5: {
  126.             if (Argument->restype == RTREAL) {
  127.                Tolerance = Argument->resval.rreal;
  128.                break;
  129.             }
  130.             else {
  131.                ads_printf("\nEEREM error:  fifth argument must be a real number\n");
  132.                return (RSERR);
  133.             }
  134.          }
  135.          default: {
  136.             ads_printf("\nEEREM error: too many arguments\n");
  137.             return (RSERR);
  138.          }
  139.       }
  140.    }
  141.  
  142.    DoEntityRemoval (SelSet);
  143.  
  144.    ads_rett();
  145.  
  146.    return (RSRSLT);
  147.  
  148. }
  149.